package com.globallogic.training.javase.money;

class Money implements Expression {

	protected int amount = 10;

	protected String currency;

	public Money(int amount, String currency) {
		this.amount = amount;
		this.currency = currency;
	}

	@Override
	public boolean equals(Object obj) {
		Money other = (Money) obj;
		return this.amount == other.amount
				&& this.currency.equals(other.currency);
	}

	protected String currency() {
		return currency;
	}

	@Override
	public Money reduce(Bank bank, String to) {
		int rate = bank.rate(currency, to);
		return new Money(amount / rate, to);
	}

	public Expression times(int multiplier) {
		return new Money(amount * multiplier, currency);
	}

	@Override
	public Expression plus(Expression other) {
		return new Sum(this, other);
	}

	static Money dollar(int amount) {
		return new Money(amount, "USD");
	}

	static Money franc(int amount) {
		return new Money(amount, "CHF");
	}

	@Override
	public String toString() {
		return "" + amount;
	}
}
